package com.safe.ocs.listeners;

import java.util.Timer;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.safe.ocs.services.FindLaterMsg;

public class LaterMsgListener implements ServletContextListener {

	private Timer timer = null;


	public void contextDestroyed(ServletContextEvent events) {
		timer.cancel();
	    events.getServletContext().log("定时器2销毁");
	}


	public void contextInitialized(ServletContextEvent events) {
		 timer = new Timer(true);
	     events.getServletContext().log("定时器2已启动");//添加日志，可在tomcat日志中查看到
	     System.out.println("定时器2已启动");
	     timer.schedule(new FindLaterMsg(),0,15*1000);//调用定时任务，0表示任务无延迟，5*1000表示每隔5秒执行任务，60*60*1000表示一个小时。
	     events.getServletContext().log("已经添加任务");

	}

}
